package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

public class AcidSkill extends BaseSkill {

    public AcidSkill(int level) {
        super(level);
    }

    public AcidSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public AcidSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return String.format("强酸技能，每次受到攻击对使用者武器额外造成（技能等级*2）伤害。");
    }

    public SkillRarity getSkillRarity() {
        return SkillRarity.Rare;
    }

    @Override
    public boolean onDamaged(LivingEntity attacker, MobEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if (attacker != null) {
            if (source.isSourceCreativePlayer() == false) {
                if (attacker.getEquippedStack(EquipmentSlot.MAINHAND) != null && source.isProjectile() == false) {
                    int MainHanddamage = attacker.getEquippedStack(EquipmentSlot.MAINHAND).getDamage();
                    attacker.getEquippedStack(EquipmentSlot.MAINHAND).damage(MainHanddamage + getSkillLevel() * 2, target, p -> p.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
                }
                if (attacker.getEquippedStack(EquipmentSlot.OFFHAND) != null && source.isProjectile() == false) {
                    int OffHanddamage = target.getEquippedStack(EquipmentSlot.OFFHAND).getDamage();
                    attacker.getEquippedStack(EquipmentSlot.OFFHAND).damage(OffHanddamage + getSkillLevel() * 2, target, p -> p.sendEquipmentBreakStatus(EquipmentSlot.OFFHAND));
                }
            }
        }
        return true;
    }
}
